<%@page import="java.io.PrintWriter"%>
<%@page import="java.util.Date"%>
<%@page import="java.io.InputStreamReader"%>
<%@page import="java.io.BufferedReader"%>
<%@page import="jxl.biff.StringHelper"%>
<%@page import="java.io.FileOutputStream"%>
<%@page import="java.io.File"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.util.Iterator"%>
<%@page import="java.util.List"%>
<%@page import="java.util.HashMap"%>
<%@page import="java.util.Map"%>
<%@page import="org.jdom.Element"%>
<%@page import="org.jdom.Document"%>
<%@page import="org.jdom.input.SAXBuilder"%>
<%@page import="java.io.InputStream"%>
<%@page import="java.net.URLEncoder"%>
<%@ page language="java" contentType="text/plain; charset=utf-8"
	pageEncoding="utf-8"%>
<%!

private String getRequestContent(HttpServletRequest request) {
	String string = "";
    if (request.getContentType() != null 
            && request.getContentType().startsWith("application/x-www-form-urlencoded"))
    {
        System.out.println("getInputStreamAsString:application/x-www-form-urlencoded");
        Map map = request.getParameterMap();
        Iterator iter = map.keySet().iterator();
        String s = "";
        while (iter.hasNext())
        {
            String key = (String) iter.next();
            String value = request.getParameter(key);
            s += value;
        }
        string = s.replace("\r", "").replace("\n", "").replace(" ", "+");
//      try
//      {
//          string = URLEncoder.encode(s.replace("\r", "").replace("\n", ""), "utf-8");
//      }
//      catch (Exception e)
//      {
//          e.printStackTrace();
//      }
    }
    else // text/xml
    {
        StringBuffer sb = new StringBuffer();
        try
        {
            InputStream in = request.getInputStream();
            BufferedReader br = new BufferedReader(new InputStreamReader(in));
            String s;
            while ((s = br.readLine()) != null){
                sb.append(s);
            }
            br.close();
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        string = sb.toString();
    }
    
    return string;
}
%>
<%
	String resp = "1";

	/*
	Map<String, String> params = new HashMap<String, String>();
	try {
		InputStream in = request.getInputStream();

		SAXBuilder saxb = new SAXBuilder();
		Document doc = saxb.build(in);
		Element root = doc.getRootElement();

		// Map<String, String> params = new HashMap<String, String>();
		List list = root.getChildren();
		String log = "[";
		for (Iterator it = list.iterator(); it.hasNext();) {
			Element elt = (Element) it.next();
			params.put(elt.getName(), elt.getText());
			if (log.length() > 1) {
				log += ";";
			}
			log += elt.getName() + ":" + elt.getText();
		}
		log += "]";
		System.out.println("mmiap: " + log);
	} catch (Exception ex) {
		System.out.println("mmiap err:" + ex.getMessage());
		// return;
	}
	*/
	try {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	        String date = sdf.format(new Date());
		File file = new File("/u02/kbox/boss/sync/rtpay/" + date.substring(0, 10) + ".txt");
		if (!file.exists()) {
			file.createNewFile();
		}
		FileOutputStream fos = new FileOutputStream(file, true);
		fos.write((date + " -- " + getRequestContent(request) + "\r\n").getBytes());
		fos.close();
	}
	catch (Exception e) {
		e.printStackTrace();
	}
	response.reset();
	PrintWriter pw = response.getWriter();
	pw.write(resp);
	pw.flush();
	pw.close();
	if (true)
		return;
	//response.getWriter().print(resp);
%>
